import axios from 'axios';

const API_BASE_URL = 'http://localhost:8001/api/';

interface ManipulateConcept {
    id?: number;
    category: string;
    concept_name: string;
    concept_description: string;
    essay_title: string;
    created_at?: string;
}

interface ManipulateEssay {
    id?: number;
    source: string;
    title: string;
    full_text: string;
    created_at?: string;
}

export const fetchConcepts = async (): Promise<ManipulateConcept[]> => {
    const response = await axios.get(`${API_BASE_URL}manipulate-mode/concepts/`);
    return response.data.results;
};

export const createConcept = async (concept: ManipulateConcept): Promise<ManipulateConcept> => {
    const response = await axios.post(`${API_BASE_URL}manipulate-mode/concepts/`, concept);
    return response.data;
};

export const updateConcept = async (id: number, concept: ManipulateConcept): Promise<ManipulateConcept> => {
    const response = await axios.put(`${API_BASE_URL}manipulate-mode/concepts/${id}/`, concept);
    return response.data;
};

export const deleteConcept = async (id: number): Promise<void> => {
    await axios.delete(`${API_BASE_URL}manipulate-mode/concepts/${id}/`);
};


//文章集部分接口
export const fetchEssays = async (): Promise<ManipulateEssay[]> => {
    const response = await axios.get(`${API_BASE_URL}manipulate-mode/essays/`);
    // console.log(response);

    return response.data;
};

export const createEssay = async (essay: ManipulateEssay): Promise<ManipulateEssay> => {
    const response = await axios.post(`${API_BASE_URL}manipulate-mode/essays/`, essay);
    return response.data;
};

export const updateEssay = async (id: number, essay: ManipulateEssay): Promise<ManipulateEssay> => {
    const response = await axios.put(`${API_BASE_URL}manipulate-mode/essays/${id}/`, essay);
    return response.data;
};

export const deleteEssay = async (id: number): Promise<void> => {
    await axios.delete(`${API_BASE_URL}manipulate-mode/essays/${id}/`);
};